import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author tyy
 * @Description TODO
 * @Since 2021/10/7
 */
public class AQSDemo {
    private static Integer count = 8;
    private static Lock lock = new ReentrantLock();

    public static void incr() {
        try {
            Thread.sleep(10);
            lock.lock();
            count++;
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }

    }

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(1000);
        for (int i = 0; i < 1000; i++) {
            new Thread(()->{
                incr();
                latch.countDown();
            }).start();
        }
        latch.await();
        System.out.println("count = " + count);

    }
}
